//
//  SISSNotificationCell.m
//  SISSAPP
//
//  Created by 优房网 on 2017/6/20.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSNotificationCell.h"

@interface SISSNotificationCell ()

/* iconImageView */
@property (weak, nonatomic) UIImageView *iconImageView;
/* title */
@property (weak, nonatomic) UILabel *titleLabel;
/* content */
@property (weak, nonatomic) UILabel *contentLabel;
/* timeLabel */
@property (weak, nonatomic) UILabel *timeLabel;
/* line */
@property (weak, nonatomic) UIView *lineView;

@end
@implementation SISSNotificationCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
}


- (void)setLatestNotiModel:(SISSLatestNotificationModel *)latestNotiModel {
    _latestNotiModel = latestNotiModel;
    self.iconImageView.image = [UIImage imageNamed:latestNotiModel.iconName];
    self.titleLabel.text = latestNotiModel.headline;
    self.contentLabel.text = latestNotiModel.title;
    self.timeLabel.text = [latestNotiModel.release_time substringToIndex:10];
}

#pragma mark - UI
- (void)initUI {
    [super initUI];
    
    // 图标
    UIImageView *iconImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:iconImageView];
    self.iconImageView = iconImageView;
    
    // 通知类型
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.font = [UIFont systemFontOfSize:17];
    titleLabel.textColor = COLOR(0x334A60);
    [self.contentView addSubview:titleLabel];
    self.titleLabel = titleLabel;
    
    // 最新时间
    UILabel *timeLabel = [[UILabel alloc] init];
    timeLabel.font = [UIFont systemFontOfSize:12];
    timeLabel.textColor = COLOR(0x8998A5);
    [self.contentView addSubview:timeLabel];
    self.timeLabel = timeLabel;
    
    // 内容
    UILabel *contentLabel = [[UILabel alloc] init];
    contentLabel.font = [UIFont systemFontOfSize:14];
    contentLabel.textColor = COLOR(0x8998A5);
    [self.contentView addSubview:contentLabel];
    self.contentLabel = contentLabel;
    
    // 底部线条
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.contentView addSubview:lineView];
    self.lineView = lineView;
    
    // 自动布局
    CGFloat margin = 8.0;
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(margin * 2);
        make.centerY.equalTo(self.contentView);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconImageView).offset(0.5 * margin);
        make.left.equalTo(self.iconImageView.mas_right).offset(margin * 2);
    }];
    
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(margin);
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.titleLabel);
        make.right.equalTo(self.contentView).offset(-margin);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.contentView);
        make.height.mas_equalTo(1);
    }];
}

@end
